package icu.javacg.storage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import icu.javacg.storage.pojo.Area;
import icu.javacg.storage.pojo.vo.ReturnResult;
import icu.javacg.storage.service.AreaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@Tag(name = "区域模块-钟庆岭")
@RestController
public class AreaController {
    @Resource
    AreaService areaService;
    @Operation(summary = "全查") //
    @GetMapping("/hello10")
    public List<Area> hello(){
        List<Area> areas = areaService.selectAll();
        return areas;
    }
    @DeleteMapping("delete")
    @Operation(summary = "删除")
    public ReturnResult<Boolean> deleteById(@RequestParam Integer id){
         boolean removeById = areaService.removeById(id);
         if (removeById){
             return new ReturnResult<>(860,"删除成功",removeById);
         }
            return new ReturnResult<>(810,"删除失败",removeById);
    }
    @PostMapping("update")
    @Operation(summary = "修改")
    public ReturnResult<Boolean> updateById(@RequestBody Area area){
         boolean update = areaService.updateById(area);
         if (update){
             return new ReturnResult<>(870,"修改成功",update);
         }
            return new ReturnResult<>(820,"修改失败",update);
    }
    @PutMapping("insert")
    @Operation(summary = "添加")
    public ReturnResult<Area> addArea(@RequestBody Area area){
        return areaService.addArea(area);
    }
    @GetMapping("pageList")
    @Operation(summary = "分页查询")
    public Page<Area> pageArea(int a,int b){
       return areaService.pageList(a,b);
    }
}
